﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DMU;
using MySql.Data.MySqlClient;

namespace DMU
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            
        }

        Service sv = new Service();
        MySqlCommandBuilder bu = new MySqlCommandBuilder();
        MySqlDataAdapter da;
        DataTable dt;
        private void Form1_Load(object sender, EventArgs e)
        {
            dt = new DataTable();
            sv.openConnect();


            MySqlCommand cmd = new MySqlCommand("select * from docgia dg", Service.cn);

            da = new MySqlDataAdapter(cmd);
            da.Fill(dt);

            MySqlCommandBuilder bui = new MySqlCommandBuilder(da);
            gridControl1.DataSource = dt;
            #region
            {
                //MySqlParameter[] pr = new MySqlParameter[3];
                //pr[0] = new MySqlParameter("madocgia", 7);
                //pr[1] = new MySqlParameter("Hoten", "Nguyễn văn ảnh");
                //pr[2] = new MySqlParameter("ngaySinh", DateTime.Now);

                //if (sv.executeNonqueryStore("themDG", pr))
                //    MessageBox.Show("Thành công");
                //gridControl1.DataSource = sv.getDatatable("loadDG", new MySqlParameter("mdg", "7"));

                //gridControl1.DataSource = sv.exportToMySQL("loadDG", new MySqlParameter("mdg", "7"));
            }
            #endregion
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            DialogResult dlgResult = dlg.ShowDialog();
            
            if (dlgResult == DialogResult.OK)
            {
                string s = dlg.FileName;
                DataTable d=sv.excelToDatatable(s, 1);
                dt.Merge(d,true);
                gridControl1.DataSource = dt;

            }
        }

        private void simpleButton2_Click(object sender, EventArgs e)
        
        {
           MessageBox.Show( da.Update(dt).ToString());
        }




        
    }
}
